Option Explicit
Dim shell, fso, procEnv

Set fso = CreateObject("Scripting.FileSystemObject")
Set shell = CreateObject("WScript.Shell")
Set procEnv = shell.Environment("PROCESS")

Dim sProgramFiles
sProgramFiles = procEnv("ProgramFiles")

If sProgramFiles = "" Then
  sProgramFiles = shell.RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\ProgramFilesDir")
End If

'MsgBox(sProgramFiles)

Dim sVsPath
sVsPath = sProgramFiles & "\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe"

If Not fso.FileExists(sVsPath) Then
    sVsPath = Replace(sVsPath, "Program Files", "Program Files (x86)")
End If

If Not fso.FileExists(sVsPath) Then
    ' Visual Studio not found!
    WScript.Quit 1
End If

'MsgBox(sVsPath)
Dim returnCode
returnCode = shell.Run("""" & sVsPath & """ /InstallVSTemplates", 0, True)

Set procEnv = Nothing
Set shell = Nothing
Set fso = Nothing